import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { PassportModule } from '@nestjs/passport';

import { JwtStrategy } from './common/strategys/jwt.strategy';
import { JwtAuthGuard } from './common/guards';

import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { HttpSuccessInterceptor } from './common/interceptor';
import { HttpExceptionFilter } from './common/exception-filters';

import { UsersModule } from './modules/users/users.module';
import { BaseModule } from './modules/base/base.module';
import { RolesModule } from './modules/roles/roles.module';
import { WebsiteTypesModule } from './modules/website-types/website-types.module';
import { WebsitesModule } from './modules/websites/websites.module';
import { MenusModule } from './modules/menus/menus.module';
import { UploadModule } from './modules/upload/upload.module';
// db.createUser({ user: "admin", pwd: "dbadmin123456", roles: [{ role: "userAdminAnyDatabase", db: "admin" }], passwordDigestor: "server" })
// db.createUser({ user: "admin", pwd: "dbadmin123456", roles: [{ role: "userAdminAnyDatabase", db: "magic-new-tab" }], passwordDigestor: "server" })

@Module({
  imports: [
    // MongoDB数据连接
    MongooseModule.forRoot(
      'mongodb://localhost:27017/magic-new-tab',
      // 'mongodb://124.221.183.172:27017/magic-new-tab',
      {
        // user: 'admin',
        // pass: 'admin123'
      },
    ),
    // 全局Token
    PassportModule.register({ defaultStrategy: 'jwt' }),
    BaseModule,
    UploadModule,
    RolesModule,
    UsersModule,
    WebsiteTypesModule,
    WebsitesModule,
    MenusModule,
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: HttpSuccessInterceptor,
    },
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter
    },
    JwtStrategy,
  ],
})
export class AppModule { }
